package logic

import (
	"ball/ballrpc/ballrpc"
	"ball/ballrpc/internal/svc"
	"ball/models/mysql"
	"context"
	"fmt"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentLogic {
	return &CommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 帖子评论
func (l *CommentLogic) Comment(in *ballrpc.CommentRequest) (*ballrpc.CommentResponse, error) {
	// todo: add your logic here and delete this line
	var post mysql.Post
	mysql.DB.Debug().Create(&post)
	if strings.Contains(in.Desc, "草") {
		return nil, fmt.Errorf("敏感词不能评论")
	}
	return &ballrpc.CommentResponse{
		Id: int64(post.ID),
	}, nil
}
